package chose;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-04-04
 * Time: 17:46
 */

//充分理解构造方法和继承
public class Test {
    public static void main(String[] args) {
        System.out.println(new B().getValue());
    }

    static class A {
        protected int value;

        public A(int v) {
            setValue(v);//5
        }

        public void setValue(int value) {
            this.value = value;//10,22,16,34
        }

        public int getValue() {
            try {
                value++;//11,17
                return value;//11,17
            } catch (Exception e) {
                System.out.println(e.toString());
            } finally {
                this.setValue(value);//11,17
                System.out.println(value);//22,34
            }
            return value;
        }
    }

    static class B extends A {
        public B() {
            super(5);
            setValue(getValue() - 3);//8
        }

        public void setValue(int value) {//5,11,8,17
            super.setValue(2 * value);//10,22,16,34
        }
    }
}
